import os


def rename_file():
    path = "D:\\ffmpeg\\rename\\2021_01_01_16_18_47\\"
    # 获取该目录下所有文件，存入列表中
    f = os.listdir(path)
    print(len(f))
    print(f[0])

    n = 0
    i = 0
    start = 248
    for i in f:
        # 设置旧文件名（就是路径+文件名）
        oldname = f[n]

        # 设置新文件名
        newname = '%06d.ts' % start
        start = start + 1
        # 用os模块中的rename方法对文件改名
        os.rename(path + oldname, path + newname)
        print(oldname, '======>', newname)
        n += 1


def write_path_to_txt():
    path = r"D:\porn\2021_01_02_17_46_26"
    # 获取该目录下所有文件，存入列表中
    paths = os.listdir(path)
    file_path = r'H:\ffmpeg\ffmpeg-4.3.1-2020-11-19-full_build\bin\file.txt'
    with open(file_path, 'a+') as f:
        for i in paths:
            full_path = path + '\\' + i
            f.write('file '+'\'' +full_path + '\''+'\n')  # 加\n换行显示


write_path_to_txt()

# ffmpeg 合成连接：https://blog.csdn.net/ybw_2569/article/details/103719593

# ffmpeg 合成命令：ffmpeg.exe -f concat -safe 0  -i file.txt -c copy out.mp4